package com.dalianpai.gulimall.order.web;

import com.alipay.api.AlipayApiException;
import com.dalianpai.gulimall.order.config.AlipayTemplate;
import com.dalianpai.gulimall.order.service.OrderService;
import com.dalianpai.gulimall.order.vo.PayVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author WGR
 * @create 2020/8/11 -- 23:22
 */
@Controller
public class PayWebController {
    
    
    @Autowired
    AlipayTemplate alipayTemplate;
    @Autowired
    OrderService orderService;

    /**
     * 1、把支付页返回给浏览器
     * 2、支付成功后，跳转到用户订单列表页面
     */
    @ResponseBody
    @GetMapping(value="/payOrder",produces = "text/html")
    public String payOrder(@RequestParam("orderSn") String OrderSn) throws AlipayApiException {
        PayVo payVo =  orderService.getOrderPay(OrderSn);
        String pay = alipayTemplate.pay(payVo);
        System.out.println(pay);
        return pay;
    }
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
}
